package upcweb.web;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import upcweb.modelo.ClsClub;
import upcweb.modelo.ClsSolicitud;
import upcweb.negocio.BsClub;

@Controller
public class ClubController {


	
	
	@RequestMapping(value = "/club" , method = RequestMethod.POST)
	protected ModelAndView club(){
		ModelAndView view = new ModelAndView("clubs/mvClub");			
		return view;
	}
	
	
	@RequestMapping(value = "/busquedaclub" , method = RequestMethod.POST)
	
	protected ModelAndView busquedaclub(HttpServletRequest request,
			HttpServletResponse response){
		
		BsClub oClub = new BsClub();
		ModelAndView view = new ModelAndView("clubs/mvClub");
		ArrayList<ClsClub> ListarClubList = new ArrayList<ClsClub>();
		
		String[] Tab = new String[2];
		ClsClub CluBE = new ClsClub();
	    CluBE.setCo_club(Integer.parseInt(request.getParameter("txh_Club")));
	    CluBE.setNo_club(request.getParameter("txt_b_club"));     
        CluBE.setTx_direccion(request.getParameter("txt_b_direccion"));
     
    
        
		if (Integer.parseInt(request.getParameter("op")) == 0){
			
			Tab[0] = "active";
			Tab[1] = "";
			
			ListarClubList = oClub.ListarClubID(CluBE);
			System.out.print(request.getParameter("op"));
			System.out.print(request.getParameter("txt_b_club"));
		}
		
		
		if (Integer.parseInt(request.getParameter("op"))!= 0 ){
			
			Tab[0] = "";
			Tab[1] = "active";
			ListarClubList = oClub.ListarClubID(CluBE);
			System.out.print(request.getParameter("op"));
			
		}
	
		
		view.addObject("busquedaclub", ListarClubList);
		view.addObject("Tab01", Tab[0]);
		view.addObject("Tab02", Tab[1]);
		
		return view;
		
	}
	
	
	
	@RequestMapping(value = "/OperacionClub", method = RequestMethod.POST)
	
	protected ModelAndView OperacionClub(HttpServletRequest request,
			HttpServletResponse response){

		  int aux=0;
          ClsClub CluBE = new ClsClub();
          
          
          CluBE.setNo_club(request.getParameter("tx_club"));
          CluBE.setTx_direccion(request.getParameter("tx_direccion"));
          CluBE.setNo_telefono(request.getParameter("tx_telefono"));
          CluBE.setTx_ciudad(request.getParameter("tx_ciudad"));
          CluBE.setFl_activo("1");
          
          System.out.print(request.getParameter("tx_club"));
    	  System.out.print(request.getParameter("tx_co_club"));
    	  System.out.print(request.getParameter("tx_telefono"));
    	  System.out.print(request.getParameter("tx_direccion"));
    	  System.out.print(request.getParameter("tx_ciudad"));
          
          
          System.out.print(request.getParameter("op"));

          BsClub oClub = new BsClub();
          
          
          
          if (Integer.parseInt(request.getParameter("op")) == 0){
        	  
        	  aux=oClub.InsertarClub(CluBE);
        	  
          }
          else if(Integer.parseInt(request.getParameter("op")) == 1)
          {
        	  CluBE.setCo_club(Integer.parseInt(request.getParameter("tx_co_club")));
        	  
        	  System.out.print(request.getParameter("op"));
        	  System.out.print(request.getParameter("tx_co_club"));
        	  
        	  aux=oClub.ModificarClub(CluBE); 
          }
          
          
          ModelAndView view = new ModelAndView("clubs/mvClub");
          
     
		
		  return view;
		
		
	}
	

	
	
	
	
}
